% Copyright (C) 2014-2022 Benjamin Born, Francesco D'Ascanio, Gernot J. Mueller, Johannes Pfeifer
%
% This is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% This code is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% For a copy of the licencse,
% see <http://www.gnu.org/licenses/>.

%% Creates Figure C.1: Sign-restriction vs. Blanchard-Perotti-based government spending
%% shocks

clear all
addpath('../Auxiliary_Files/')
if ~isfolder('Figures')
    mkdir('.','Figures');
end

load('dataset_BDMP.mat')
temp=load('../Sign_restriction_first_stage_shocks_euro_area/results/structural_shocks_point.mat'); %contains timeline

data_array_for_regression_stacked_by_variable = cat(3,data_array_for_regression_stacked_by_variable,temp.structural_shocks.BP_G,temp.structural_shocks.BP_T,temp.structural_shocks.PF_G,temp.structural_shocks.PF_T);
pos.BP_shock_G_CK=length(fieldnames(pos))+1;
Header{1,pos.BP_shock_G_CK}='BP_shock G based on Caldara/Kamps';
pos.BP_shock_T_CK=length(fieldnames(pos))+1;
Header{1,pos.BP_shock_T_CK}='BP_shock T based on Caldara/Kamps';
pos.PF_shock_G=length(fieldnames(pos))+1;
Header{1,pos.PF_shock_G}='Sign restriction shock G based on Caldara/Kamps';
pos.PF_shock_T=length(fieldnames(pos))+1;
Header{1,pos.PF_shock_T}='Sign restriction shock T based on Caldara/Kamps';

timeline=squeeze(data_array_for_regression_stacked_by_variable(:,1,pos.timeline));

NaN_indicator=any(isnan(data_array_for_regression_stacked_by_variable(:,:,...
    [pos.PF_shock_G,pos.BP_shock_G_CK])),3);

%% BP/OE
data_mat=data_array_for_regression_stacked_by_variable(:,:,[pos.PF_shock_G,pos.BP_shock_G_CK]);
data_mat(repmat(NaN_indicator,1,1,size(data_mat,3)))=NaN;
NaN_countries=find(all(all(isnan(data_mat),1),3));
data_mat(:,NaN_countries,:)=[];
country_header_temp=country_header;
country_header_temp(NaN_countries)=[];
plot_data(data_mat,country_header_temp,timeline,'PF_BP_',{'Sign restriction','Blanchard/Perotti'},[1999 2018.75])